//
// @Auther: by wujehy 
// @Email:wujehy@qq.com
// @Data:2019/10/08
// @Time:10:33 上午
//
//

#ifndef MQTT_PLUGIN_SQLITEAUTHPLUGIN_H
#define MQTT_PLUGIN_SQLITEAUTHPLUGIN_H

#include "AuthPluginInterface.h"
#include <string>
#include <mutex>
namespace SQLite
{
    class Database;
}

class UserDB;
class AclDB;
class SqliteAuthPlugin : public AuthPluginInterface
{
    std::string baseName = "system.db"; ///< 默认 数据库文件
    SQLite::Database *m_sys_database = nullptr;
    std::mutex db_mutex;
    UserDB *userDb = nullptr;
    AclDB *aclDb = nullptr;
public:
    SqliteAuthPlugin();

    int checkUser(const std::string &username, const std::string &password) override;

    int getPskKey(mosquitto *client, const char *hint, const char *identity, char *key, int max_key_len) override;

    int checkAcl(mosquitto *client, ACLTypeEnum access, const mosquitto_acl_msg *msg) override;

    int cleanupSecurity(mosquitto_opt *auth_opts, int auth_opts_count, bool reload) override;

    int initSecurity(mosquitto_opt *auth_opts, int auth_opts_count, bool reload) override;

    void init() override;

    virtual ~SqliteAuthPlugin();
};


#endif //MQTT_PLUGIN_SQLITEAUTHPLUGIN_H
